package com.sample.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;

import com.sample.cache.CacheService;
import com.sample.cache.CacheService.CacheServiceInner;
import com.swak.App;
import com.swak.annotation.Get;
import com.swak.annotation.RestService;
import com.swak.entity.Result;
import com.swak.utils.Fmt;
import com.swak.utils.StringUtils;

/**
 * 描述
 * 
 * @author Auto Generator
 * @date 2022-04-21T20:47:07.509267200
 */
@RestService(path = "/api/swak/cache", value = "swakCacheApi")
public class CacheApi {
	@Autowired
	private ApplicationContext context;
	@Autowired
	private CacheService cacheService;
	@Autowired
	private CacheServiceInner cacheServiceInner;

	@Get("/delete")
	public Result<Void> delete() {

		// 调起服务
		System.out.println("Thread: " + Thread.currentThread().getName());
		this.cacheService.delete();
		this.cacheServiceInner.delete();

		// 获取内部类实例
		Object service = App.getBean(CacheServiceInner.class);
		System.out.println(service);

		// 获取内部类实例
		service = App.getBean(CacheService.class);
		System.out.println(service);

		Fmt.out.println("####### 分割 #######");

		String[] beanDefinitionNames = context.getBeanDefinitionNames();
		for (String beanDefinitionName : beanDefinitionNames) {
			if (StringUtils.startsWith(beanDefinitionName, "org.springframework")) {
				continue;
			}
			if (StringUtils.startsWith(beanDefinitionName, "com.swak.boot")) {
				continue;
			}
			Object bean = context.getBean(beanDefinitionName);
			System.out.println(beanDefinitionName + " : " + bean);
		}

		return Result.success();
	}
}
